#! /bin/csh -f

##########################################################
#
#       Check Operating System version #
#
##########################################################

setenv OSVERSION `/sbin/uname -r`

@ ver = `/sbin/uname -r | cut -c1,3`
setenv OSVER $ver

if ($ver <= 52 || $ver == 60 || $ver >= 63)  then
        set answer = `$HOTMIXDIR/.all/bin/wrongOS`
        if ($answer == 0) then 
                echo " "
                echo "EXITing, Good-Bye"
                echo " "
                exit 0
        endif
endif

##########################################################
#
#       Set envir variables
#
##########################################################

unalias *
alias cd cd
set filec
setenv USERNAME `/usr/bin/whoami`
setenv HOSTNAME `/sbin/uname -n`
setenv DOMAINNAME `domainname`
##########################################################
#
#      NEED to find a writeable tmp directory
#
##########################################################

        if (-w /usr/tmp) then
           setenv TMPFILEDIR "/usr/tmp"
        else if (-w /tmp) then
           setenv TMPFILEDIR "/tmp"
        else if (-w $HOME) then
           setenv TMPFILEDIR $HOME
        endif

if (-e $TMPFILEDIR/showmess && -x $TMPFILEDIR/showmess) then
    setenv SHOWMESS $TMPFILEDIR/showmess
else
    if (-e $TMPFILEDIR/showmess && ! -w $TMPFILEDIR/showmess) then
echo Using CD version
        setenv SHOWMESS $HOTMIXDIR/.all/bin/showmess
    else
        cp $HOTMIXDIR/.all/bin/showmess $TMPFILEDIR
        setenv SHOWMESS $TMPFILEDIR/showmess
    endif
endif

setenv TMPFILE $TMPFILEDIR/.HM14_`date $* | sed -e 's/ //g'`
setenv HM14LOG $TMPFILEDIR/HM14LOGFILE.`date $* | sed -e 's/ //g'`

#--------------------------------
#   write header to tmpfile
#--------------------------------
echo '\n'      >> $TMPFILE
echo 'MeFr:\c' >> $TMPFILE
#--------------------------------


echo `date` > $HM14LOG
echo "=============================================" >> $HM14LOG
echo " " >> $HM14LOG
touch $TMPFILE
echo TMPFILEDIR=$TMPFILEDIR >> $HM14LOG

echo OSVERSION=$OSVERSION >> $HM14LOG

set path=($path /usr/bin/X11 /usr/sbin . $TMPFILEDIR $HOTMIXDIR/.all/bin)
echo " " >> $HM14LOG
echo "Appending /usr/bin/X11 /usr/sbin . $TMPFILEDIR $HOTMIXDIR/.all/bin  to PATH" >> $HM14LOG
echo "PATH=$PATH" >> $HM14LOG
echo "============="  >> $HM14LOG
echo " "  >> $HM14LOG

# $HOTMIXDIR/.all/bin/InstallIt

##########################################################
#
#       Set the (app-defaults, X-resources, $path) paths 
#
##########################################################
if !(-e "$HOME/CosmoPlayer") then
   if (-w $HOME) then
   	if (-e /usr/lib/X11/app-defaults/CosmoPlayer) then
		cp $HOTMIXDIR/.all/bin/netscape/CosmoPlayer $HOME
	else
		echo " "
		echo 'Cannot find app-default file for CosmoPlayer'
		echo '    please install from CD-ROM or http://www.vrml.com '
		echo " "
	endif
   endif
endif

if ( ! ${?XUSERFILESEARCHPATH} ) then
  	setenv XUSERFILESEARCHPATH "$HOME/.desktop-`hostname`/%N:$HOTMIXDIR/.all/bin/%N:$HOME/%N:/usr/lib/X11/app-defaults/%N"
  	echo XUSERFILESEARCHPATH is not set, setting it to $XUSERFILESEARCHPATH >> $HM14LOG
  	echo "============="  >> $HM14LOG
  	echo " "  >> $HM14LOG
else
  	echo "XUSERFILESEARCHPATH is set.. " >> $HM14LOG
  	setenv XUSERFILESEARCHPATH "$HOME/.desktop-`hostname`/%N:$HOME/%N:$HOTMIXDIR/.all/bin/%N:/usr/lib/X11/app-defaults/%N:/usr/lib/X11/app-defaults/%L/%N%C:/usr/lib/X11/app-defaults/%l/%N%C:/usr/lib/X11/app-defaults/%N%C:/usr/lib/X11/app-defaults/%L/%N:/usr/lib/X11/app-defaults/%l/%N:${XUSERFILESEARCHPATH}"
#  	setenv XUSERFILESEARCHPATH "$HOME/.desktop-`hostname`/%N:$HOTMIXDIR/.all/bin/%N:/usr/lib/X11/app-defaults/%N:${XUSERFILESEARCHPATH}"
  	echo "  ADDING $HOME/.desktop-`hostname`/%N:$HOTMIXDIR/.all/bin/%N:/usr/lib/X11/app-defaults/%N" >> $HM14LOG
	echo XUSERFILESEARCHPATH=$XUSERFILESEARCHPATH >> $HM14LOG
  	echo "============="  >> $HM14LOG
  	echo " "  >> $HM14LOG
endif

if ( ! ${?XFILESEARCHPATH} ) then
   	setenv XFILESEARCHPATH "$HOME/.desktop-`hostname`/%N:$HOTMIXDIR/.all/bin/%N:$HOME/%N:/usr/lib/X11/app-defaults/%N "
   	echo "XFILESEARCHPATH is not set, setting it as below:" >> $HM14LOG
   	echo "XFILESEARCHPATH = $XFILESEARCHPATH" >> $HM14LOG
  	echo "============="  >> $HM14LOG
  	echo " "  >> $HM14LOG
else
   	setenv XFILESEARCHPATH "$HOME/.desktop-`hostname`/%N:$HOTMIXDIR/.all/bin/%N:$HOME/%N:/usr/lib/X11/app-defaults/%N:${XFILESEARCHPATH}"
   	echo adding $HOTMIXDIR/.all/bin AND $HOME to XFILESEARCHPATH >> $HM14LOG
  	echo "============="  >> $HM14LOG
  	echo " "  >> $HM14LOG
endif

##########################################################
#
#       Set path for libraries
#
##########################################################

setenv CLASSPATH $HOTMIXDIR/bin/classes:$HOTMIXDIR/.all/bin/netscape/Cosmo3D_Demos/classes:.

# if ( ! ${?LD_LIBRARY_PATH} ) then
#   echo LD_LIBRARY_PATH is NOT set 
#    setenv LD_LIBRARY_PATH $HOTMIXDIR/.all/bin:/usr/lib:/lib:/lib/cc:/usr/lib/cc:/usr/local/lib:$HOTMIXDIR/.all/bin/netscape/Cosmo3D_Demos/lib:$TMPFILEDIR
# else
#   echo LD_LIBRARY_PATH is already set 
#    setenv LD_LIBRARY_PATH $HOTMIXDIR/.all/bin:${LD_LIBRARY_PATH}:$HOTMIXDIR/.all/bin/netscape/Cosmo3D_Demos/lib:$TMPFILEDIR
# endif
#
# echo Setting LD_LIBRARY_PATH=$LD_LIBRARY_PATH 

##########################################################
#
#       Startup the intro movie 
#
##########################################################

if !(-e "/usr/sbin/movieplayer") then
   # Cannot find Movieplayer in /usr/sbin/movieplayer
   if (-e `which movieplayer`) then
      `which movieplayer` -f -D -v -l 1 -S 200,200 $HOTMIXDIR/HTML/hotmix.qt 
   endif
else
   /usr/sbin/movieplayer -f -D -v -l 1 -S 200,200  $HOTMIXDIR/HTML/hotmix.qt
   # Found Movieplayer in /usr/sbin/movieplayer
endif

##########################################################
#
#       Set environ for netscape
#
##########################################################
LOOP:
if (-e "$HOME/.netscape/") then
  if (-w "$HOME/.netscape/") then
        if (-e "$HOME/.netscape/preferences") then
                nawk -f $HOTMIXDIR/.all/bin/awkzilla.awk \
				       $HOME/.netscape/preferences \
				     > $HOME/.netscape/preferehm14
                chmod 777 $HOME/.netscape/preferehm14
        else
                nawk -f $HOTMIXDIR/.all/bin/awkzilla.awk \
			$HOTMIXDIR/.all/bin/netscape/preferehm14 \
			> $HOME/.netscape/preferehm14
                chmod 777 $HOME/.netscape/preferehm14
        endif
	if (! -e "$HOME/.netscape/moz2_01.zip") then
        	cp $HOTMIXDIR/.all/bin/moz2_01.zip $HOME/.netscape/
	endif

  else 
	/usr/bin/X11/xconfirm -icon warning \
        -t "Cannot Write to the $HOME directory" \
        -t " " \
        -t "You need to have write permissions for the $HOME home directory\!" \
        -t "This will end this session of Hot Mix...." \
        -t " " \
        -b Ok
        exit 
  endif
else
  if (-w $HOME) then
        mkdir $HOME/.netscape/
       	if (-e "$HOME/.netscape-preferences") then
        	setenv ORIGSOCKSHOSTS `grep SOCKS_HOST $HOME/.netscape-preferences|awk '{print $2}'`
        	echo ORIGSOCKSHOSTS=$ORIGSOCKSHOSTS
        	nawk -f $HOTMIXDIR/.all/bin/awkzilla2.awk \
        		$HOTMIXDIR/.all/bin/netscape/preferehm14 \
        		> $HOME/.netscape/preferences
        endif
        goto LOOP
  else 
        /usr/bin/X11/xconfirm -icon warning \
        -t "Cannot Write to the $HOME directory" \
        -t " " \
        -t "You need to have write permissions for the $HOME home directory\!" \
        -t "This will end this session of Hot Mix...." \
        -t " " \
        -b Ok
        exit
  endif 
endif

cd $HOTMIXDIR/.all/bin/netscape 

if ($ver >= 62)  then
   ./netscape.62 -geometry 877x960 -xrm "*strings.22130:This process will either Install, Remove, or Launch\nsoftware from the Hot Mix 14 CD.\n\nProceed?\n" file:$HOTMIXDIR/HTML/index.html
else
   ./netscape.53 -geometry 877x900 -xrm "*strings.22130:This process will either Install, Remove, or Launch\nsoftware from the Hot Mix 14 CD.\n\nProceed?\n" file:$HOTMIXDIR/HTML/index.html
endif

##########################################################
#
#       Start Email reply card 
#
##########################################################

if (-e $TMPFILEDIR/.hm14lock) then

       setenv resend `xconfirm -c -t 'Someone on this machine has already registered' -t 'to receive future Hot Mix volumes.' -t ' ' -t 'Do you want to register again?' -icon info -b No -B Yes`

        switch ($resend)
             case Yes:
                    cd $HOTMIXDIR/.all/bin
                    $HOTMIXDIR/.all/bin/Email.online
                    breaksw
             case No:
                    breaksw
        endsw
else
        cd $HOTMIXDIR/.all/bin
        $HOTMIXDIR/.all/bin/Email.online
endif

##########################################################
#
#       Clean up
#
##########################################################
CLEANUP:
if ( -e $TMPFILE && -w $TMPFILE) then
        \rm -rf $TMPFILE
endif

if ( -e $HM14LOG && -w $HM14LOG) then
        \rm -rf $HM14LOG
endif

if ( -e $HOME/CosmoPlayer && -w $HOME/CosmoPlayer) then
        \rm -rf $HOME/CosmoPlayer
endif

exit

